package com.admin.business.venusOrganizeDepartment;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 部门信息表
 * @create: 2022-03-22 18:46:06
 **/
@Service("venusOrganizeDepartment")
@Slf4j
public class VenusOrganizeDepartmentService{

    @Resource
    VenusOrganizeDepartmentDao venusOrganizeDepartmentDao;

    /**
     * 添加部门信息表,获取dept_id数据
     *
     * @param cdoRequest - dept_id:
     *                   - dept_code:部门编码
     *                   - dept_name:部门名称
     *                   - dept_parent_id:部门父id
     *                   - dept_sys_user_id:部门负责人
     *                   - dept_predict_num_people:预计人数
     *                   - org_id:公司ID
     *                   - dept_project_id:项目Id
     *                   - dept_sign:0正常部门，1代表给公司关联的部门
     *                   - dept_responsibility:部门职责
     *                   - dept_state:0正常，2删除
     *                   - dept_user_id:创建人id
     *                   - dept_tel:部门电话
     *                   - dept_num:部门人数
     *                   - dept_update_time:修改时间
     *                   - dept_update_user:修改人
     *                   - dept_report_user:部门汇报人
     *                   - dept_create_time:创建时间
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return addVenusOrganizeDepartment(CDO cdoRequest) {
        venusOrganizeDepartmentDao.addVenusOrganizeDepartment(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("dept_id")) {
            cdoResult.set("dept_id", cdoRequest.get("dept_id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据dept_id，更新部门信息表数据
     *
     * @param cdoRequest - dept_id:
     *                   - dept_code:部门编码
     *                   - dept_name:部门名称
     *                   - dept_parent_id:部门父id
     *                   - dept_sys_user_id:部门负责人
     *                   - dept_predict_num_people:预计人数
     *                   - org_id:公司ID
     *                   - dept_project_id:项目Id
     *                   - dept_sign:0正常部门，1代表给公司关联的部门
     *                   - dept_responsibility:部门职责
     *                   - dept_state:0正常，2删除
     *                   - dept_user_id:创建人id
     *                   - dept_tel:部门电话
     *                   - dept_num:部门人数
     *                   - dept_update_time:修改时间
     *                   - dept_update_user:修改人
     *                   - dept_report_user:部门汇报人
     *                   - dept_create_time:创建时间
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return updateVenusOrganizeDepartmentById(CDO cdoRequest) {
        int affectedRows = venusOrganizeDepartmentDao.updateVenusOrganizeDepartmentById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据dept_id，删除部门信息表数据
     *
     * @param cdoRequest - dept_id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusOrganizeDepartmentById(CDO cdoRequest){
        int affectedRows = venusOrganizeDepartmentDao.deleteVenusOrganizeDepartmentById(cdoRequest.getInteger("dept_id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除部门信息表数据
     *
     * @param cdoRequest - dept_code:部门编码
     *                   - dept_name:部门名称
     *                   - dept_parent_id:部门父id
     *                   - dept_sys_user_id:部门负责人
     *                   - org_id:公司ID
     *                   - dept_user_id:创建人id
     *                   - dept_create_time:创建时间
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return deleteVenusOrganizeDepartment(CDO cdoRequest) {
        int affectedRows = venusOrganizeDepartmentDao.deleteVenusOrganizeDepartment(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取部门信息表数据
     *
     * @param cdoRequest - dept_id:
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizeDepartmentById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOrganizeDepartmentDao.getVenusOrganizeDepartmentById(cdoRequest.getInteger("dept_id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取部门信息表数据
     *
     * @param cdoRequest - dept_id:
     *                   - dept_code:部门编码
     *                   - dept_name:部门名称
     *                   - dept_parent_id:部门父id
     *                   - dept_sys_user_id:部门负责人
     *                   - org_id:公司ID
     *                   - dept_user_id:创建人id
     *                   - dept_create_time:创建时间
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizeDepartment(CDO cdoRequest) {
        CDO cdoMapperResult = venusOrganizeDepartmentDao.getVenusOrganizeDepartment(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取部门信息表数据列表
     *
     * @param cdoRequest - dept_code:部门编码
     *                   - dept_name:部门名称
     *                   - dept_parent_id:部门父id
     *                   - dept_sys_user_id:部门负责人
     *                   - org_id:公司ID
     *                   - dept_user_id:创建人id
     *                   - dept_create_time:创建时间
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizeDepartmentList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrganizeDepartmentDao.getVenusOrganizeDepartmentList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取部门信息表数据列表
     *
     * @param cdoRequest - dept_id:
     *                   - dept_code:部门编码
     *                   - dept_name:部门名称
     *                   - dept_parent_id:部门父id
     *                   - dept_sys_user_id:部门负责人
     *                   - org_id:公司ID
     *                   - dept_user_id:创建人id
     *                   - dept_create_time:创建时间
     *                   - project_id:项目id
     * @return
     * @author ht
     * @create: 2022-03-22 18:46:06
     */
    @OpenApi
    public Return getVenusOrganizeDepartmentListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOrganizeDepartmentDao.getVenusOrganizeDepartmentListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
        return Return.valueOf(cdoResult);
    }
}
